//确定四个点的中心线void sortCorners(std::vector& corners,cv::Point2f center){std::vector top, bot;vector backup = corners;
sort(corners, x_sort); //注意先按x的大小给4个点排序
for (int i = 0; i < corners.size(); i++){if (corners[i].y < center.y && top.size() < 2)//这里的小于2是为了避免三个顶点都在top的情况top.push_back(corners[i]);elsebot.push_back(corners[i]);}corners.clear();
if (top.size() == 2 && bot.size() == 2) {//cout top[1].x ? top[0] : top[1];cv::Point2f bl = bot[0].x > bot[1].x ? bot[1] : bot[0];cv::Point2f br = bot[0].x > bot[1].x ? bot[0] : bot[1];
corners.push_back(tl);corners.push_back(tr);corners.push_back(br);corners.push_back(bl);}else{corners = backup;}}